@extends('layouts.app')

@section('content')
<!-- Main content -->
<section class="content">
  <div class="row">
    <div class="col-xs-12">
      @include('layouts.utils.success')
      <div class="box">
        <div class="box-header">
          <a href="{{ url('/api_admin/managers/create' )}}" class="btn btn-primary">添加新管理员</a>
          <!-- <div class="box-tools">
            <div class="input-group input-group-sm" style="width: 150px;">
              <input type="text" name="table_search" class="form-control pull-right" placeholder="Search">

              <div class="input-group-btn">
                <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
              </div>
            </div>
          </div> -->
        </div>
        <!-- /.box-header -->
        <div class="box-body table-responsive no-padding">
          <table class="table table-hover">
            <tr>
              <th style="width: 100px">ID</th>
              <th>用户名</th>
              <th>邮箱</th>
              <th>创建日期</th>
              <th>角色</th>
              <th style="width: 100px">操作</th>
            </tr>
            @forelse ($admins as $admin)
              <tr>
                <td>{{ $admin->id }}</td>
                <td>
                  <a href="{{ url('/api_admin/managers/'.$admin->id.'/edit')}}">{{ $admin->name }}</a>
                </td>
                <td>{{ $admin->email }}</td>
                <td>{{ $admin->created_at }}</td>
                <td>
                  @if(count($admin->roles))
                    @foreach($admin->roles as $role)
                      <span class="label label-success">{{ $role->display_name }}</span>
                    @endforeach
                  @else
                    无角色
                  @endif
                </td>
                <td>
                  <a style="cursor: pointer;" onclick="del({{$admin->id}})">删除</a>
                  <form id="del-{{ $admin->id }}" method="post" action="{{ url('/api_admin/managers/'.$admin->id) }}">
                    {!! csrf_field() !!}
                    {{ method_field('DELETE') }}
                  </form>
                </td>
              </tr>
            @empty
              <tr>
                <td colspan="7" class="text-center">暂无数据</td>
              </tr>
            @endforelse
          </table>
          @include('layouts.utils.del_modal', ['title' => '用户'])
        </div>
        <div class="box-footer">
          {!! $admins->links() !!}
        </div>
        <!-- /.box-body -->
      </div>
      <!-- /.box -->
    </div>
  </div>
</section>
<!-- /.content -->
@endsection

@section('js')
<script type="text/javascript">
  function del(id){
    var formId = 'del-'+id;
    $('#delete-modal').modal();
    $('#del-btn').on('click', function() {
      $('#'+formId).submit();
    });
  }
</script>
@endsection
